#'
#' Loosmore goodness of fit test
#'
#' @param Kfuns a matrix, each column contains an values of summary statistics for observed (the first column) and null communities (other columns)
#'
#'
#'
#'
#'
#'@export
lmGofTest=function(Kfuns){
  nsim=dim(Kfuns)[2]
  
  hsum=apply(Kfuns,1,sum,na.rm=TRUE)
  hmean=(hsum-Kfuns)/nsim
  
  ui=apply((Kfuns-hmean)^2,2,sum,na.rm=TRUE)
  pvalue=1-sum(ui[1]>ui[-1])/nsim
  
  return(pvalue)
}